package util;

import bean.PeskResponseEntity;
import bean.ResponseCode;

/**
 * @author xwu36
 */
public class ResponseUtil {

    /**
     * 成功的创建json信息
     *
     * @param data 参数
     * @param <T>  泛型
     * @return json
     */
    public static <T> PeskResponseEntity success(T data) {
        return new PeskResponseEntity<>(ResponseCode.Success.getCode(), ResponseCode.Success.getMsg(), data);
    }

    public static <T> PeskResponseEntity success() {
        return new PeskResponseEntity<>(ResponseCode.Success.getCode(), ResponseCode.Success.getMsg(), null);
    }

    public static <T> PeskResponseEntity fail() {
        return new PeskResponseEntity<>(ResponseCode.Fail.getCode(), ResponseCode.Fail.getMsg(), null);
    }

    public static <T> PeskResponseEntity fail(String msg) {
        return new PeskResponseEntity<>(ResponseCode.Fail.getCode(), msg, null);
    }

    public static <T> PeskResponseEntity Unauthorized() {
        return new PeskResponseEntity<>(ResponseCode.Unauthorized.getCode(), ResponseCode.Unauthorized.getMsg(), null);
    }

    public static <T> PeskResponseEntity forbidden() {
        return new PeskResponseEntity<>(ResponseCode.Forbidden.getCode(), ResponseCode.Forbidden.getMsg(), null);
    }

    public static <T> PeskResponseEntity create(int code, String msg, T data) {
        return new PeskResponseEntity<>(code, msg, data);
    }
}
